<?php
namespace app\servercertificate\logic;
use \app\manage\logic\BaseLogic;
/**
 * @author:      李颖
 * @DateTime:    2017-12-22 14:37:39
 * @Description: 证书的积分派发记录
 */
class CertificateIntegralDistribute extends BaseLogic
{
	protected $name = 'certificate_integral_distribute';
    protected $config = 'db_config_certificate';
    protected $certificateIntegralDistributeModel = 'app\servercertificate\model\CertificateIntegralDistribute';
    protected $certificateModel = 'app\servercertificate\model\Certificate';


    /*获取我的昨日收益总计*/
    public function myYesterdayEarnings($data): array 
    {
		$yesterdayDate = date("Y-m-d",strtotime("-1 day"));  //昨天0点时间格式
		$yesterdayTime = strtotime($yesterdayDate); //昨天0点时间戳
		$nowStartTime = strtotime(date("Y-m-d"));  //今天0点时间戳格式
    	//获取我的所有高级证书的Id
    	$_where['user_id'] = $data['user_id'];
    	$_where['type'] = 'advanced';
    	$_where['is_pick'] = 0;
    	$_where['status'] = 1;
    	$_where['finish_distribute_time'] = ['gt', $yesterdayDate];  //收益结束时间大于昨天0点
    	$_where['create_time'] = ['lt', $nowStartTime];  //创建时间小于今天0点
    	$certificateIds = $this->model($this->certificateModel)->where($_where)->column('id');
    	//获取我昨日的累计收益
    	$_earnWhere['certificate_id'] = ['in', $certificateIds];
    	$_earnWhere['certificate_user_id'] = $data['user_id'];
    	$_earnWhere['distribute_date'] = $yesterdayDate;
    	$_earnWhere['status'] = 1;
    	$yesterdayEarn = $this->model($this->certificateIntegralDistributeModel)->where($_earnWhere)->sum('integral');
        if(!$yesterdayEarn){ $yesterdayEarn = 0; }
    	return auto_return($yesterdayEarn);
    }

}